package com.example.photography.fragment.product;

import android.widget.GridView;

import androidx.core.view.ViewCompat;

import com.alibaba.fastjson.JSONObject;
import com.example.photography.R;
import com.example.photography.adapter.product.PictureAdapter;
import com.example.photography.bean.PicturesBean;
import com.example.photography.bean.ProductBean;
import com.example.photography.common.BaseFragment;
import com.example.photography.util.Util;
import com.loopj.android.http.RequestParams;

import java.util.List;
import java.util.Objects;

import butterknife.BindView;

import static com.example.photography.util.Util.getJson;

public class Product_Picture extends BaseFragment {
    @BindView(R.id.gv_item)
    GridView gvItem;
    private List<PicturesBean.DataBean.PictureBean> pictureBeanList;
    private PicturesBean picturesBean;
    public Product_Picture() {
    }


    @Override
    protected RequestParams getParams() {
        return null;
    }

    @Override
    protected String getUrl() {
        return null;
    }

    @Override
    protected void initData(String content) {
        //CollapsingToolbarLayout展开/折叠
        ViewCompat.setNestedScrollingEnabled(gvItem,true);

        String json = getJson(Objects.requireNonNull(getActivity()), "picture.json");
        if (!json.isEmpty()) {
            picturesBean = JSONObject.parseObject(json, PicturesBean.class);
        }
        pictureBeanList = picturesBean.getData().getPicture();
        PictureAdapter pictureAdapter = new PictureAdapter(pictureBeanList, getActivity()) {
            @Override
            public void setItemListen(int id) {
                Util.showToast(getActivity(), "item_id:" + id);
            }
        };
        gvItem.setAdapter(pictureAdapter);
    }

    @Override
    public int getLayoutId() {
        return R.layout.product_article;
    }
}
